Zephyr API Documentation: GPIO Driver APIs 您所在的位置:网站首页 Zephyr API Documentation Defines and Assigned Numbers Zephyr API Documentation: GPIO Driver APIs

Zephyr API Documentation: GPIO Driver APIs

2024-06-17 09:36| 来源: 网络整理| 查看: 265

#include

Value: ((gpio_port_pins_t) \ COND_CODE_1(DT_NODE_HAS_PROP(node_id, gpio_reserved_ranges), \ (GENMASK64(BITS_PER_LONG_LONG - 1, ngpios) \ | FOR_EACH_FIXED_ARG(Z_GPIO_GEN_RESERVED_RANGES_COND, \ (|), \ node_id, \ LIST_DROP_EMPTY(Z_SPARSE_LIST_ODD_NUMBERS))), \ (0))) FOR_EACH_FIXED_ARG#define FOR_EACH_FIXED_ARG(F, sep, fixed_arg,...)Call macro F on each provided argument, with an additional fixed argument as a parameter.Definition: util_macro.h:585 LIST_DROP_EMPTY#define LIST_DROP_EMPTY(...)Remove empty arguments from list.Definition: util_macro.h:315 BITS_PER_LONG_LONG#define BITS_PER_LONG_LONGNumber of bits in a long long int.Definition: util.h:64

Makes a bitmask of reserved GPIOs from DT "gpio-reserved-ranges" property and "ngpios" argument.

This macro returns the value as a bitmask of the "gpio-reserved-ranges" property. This property defines the disabled (or 'reserved') GPIOs in the range 0...ngpios-1 and is specified as an array of value's pairs that define the start offset and size of the reserved ranges.

For example, setting "gpio-reserved-ranges = , ;" means that GPIO offsets 3, 4 and 10 cannot be used even if ngpios = .

The implementation constraint is inherited from common DT limitations: a maximum of 64 pairs can be used (with result limited to bitsize of gpio_port_pins_t type).

NB: Due to the nature of C macros, some incorrect tuple definitions (for example, overlapping or out of range) will produce undefined results.

Also be aware that if ngpios is less than 32 (bit size of DT int type), then all unused MSBs outside the range defined by ngpios will be marked as reserved too.

Example devicetree fragment:

a { compatible = "some,gpio-controller"; ngpios = ; gpio-reserved-ranges = , , , , , , , , , ; }; b { compatible = "some,gpio-controller"; ngpios = ; gpio-reserved-ranges = , ; };

Example usage:

struct some_config { uint32_t ngpios; uint32_t gpios_reserved; }; static const struct some_config dev_cfg_a = { .ngpios = DT_PROP_OR(DT_LABEL(a), ngpios, 0), .gpios_reserved = GPIO_DT_RESERVED_RANGES_NGPIOS(DT_LABEL(a), DT_PROP(DT_LABEL(a), ngpios)), }; static const struct some_config dev_cfg_b = { .ngpios = DT_PROP_OR(DT_LABEL(b), ngpios, 0), .gpios_reserved = GPIO_DT_RESERVED_RANGES_NGPIOS(DT_LABEL(b), DT_PROP(DT_LABEL(b), ngpios)), }; DT_PROP_OR#define DT_PROP_OR(node_id, prop, default_value)Like DT_PROP(), but with a fallback to default_value.Definition: devicetree.h:825 DT_PROP#define DT_PROP(node_id, prop)Get a devicetree property value.Definition: devicetree.h:663

This expands to:

struct some_config { uint32_t ngpios; uint32_t gpios_reserved; }; static const struct some_config dev_cfg_a = { .ngpios = 32, .gpios_reserved = 0xdeadbeef, // 0b1101 1110 1010 1101 1011 1110 1110 1111 static const struct some_config dev_cfg_b = { .ngpios = 18, .gpios_reserved = 0xfffc0418, // 0b1111 1111 1111 1100 0000 0100 0001 1000 // unused MSBs were marked as reserved too }; Parameters node_idGPIO controller node identifier. ngpiosnumber of GPIOs. Returnsthe bitmask of reserved gpios


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有